package gui;

import javax.swing.DefaultListModel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import ctr.RRctr;
import model.Room;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

public class ShowAvailable extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4511800869174674023L;
	private JTextField inField;
	private JTextField outField;
	private JList lstRooms;

	/**
	 * Create the panel.
	 */
	public ShowAvailable() {
		setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(0, 0, 450, 224);
		add(scrollPane);
		
		 lstRooms = new JList();
		scrollPane.setViewportView(lstRooms);
		
		JButton btnNewButton = new JButton("Update List");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				updateRoomList();
			}
		});
		btnNewButton.setBounds(341, 261, 97, 25);
		add(btnNewButton);
		
		JLabel lblCheckin = new JLabel("CheckIn");
		lblCheckin.setBounds(10, 237, 56, 16);
		add(lblCheckin);
		
		inField = new JTextField();
		inField.setBounds(69, 234, 116, 22);
		add(inField);
		inField.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("CheckOut");
		lblNewLabel.setBounds(10, 265, 56, 16);
		add(lblNewLabel);
		
		outField = new JTextField();
		outField.setBounds(69, 262, 116, 22);
		add(outField);
		outField.setColumns(10);

	}
	
	private void updateRoomList()
	{
		String checkIn = inField.getText();
		String checkOut = outField.getText();
		ArrayList<Room> list = new RRctr().findEmptyRooms(checkIn, checkOut);
		DefaultListModel<Room> dlist = new DefaultListModel<>();
		for(Room room: list)
			dlist.addElement(room);
		lstRooms.setModel(dlist);
	}

}
